<?php
require_once 'libs/twitter/Trends.class.php';
require_once 'libs/twitter/Trend.class.php';
require_once 'libs/twitter/Location.class.php';
require_once 'business/UserBusiness.class.php';


class TrendsBusiness{

	protected $user = null;
	protected $twitterObj = null;

	/**
	 * Contructor de la clase
	 *
	 */
	public function __construct($user, $twitterObj){
		$this->user = $user;
		$this->twitterObj = $twitterObj;
	}


	//METODOS PUBLICOS
	public function getTrends($woeid=1){
		//get the user trends location
//		$userBusiness = new UserBusiness($this->user, $this->twitterObj);
//		$userSettings = $userBusiness->getSettings();

		$parametros = array($woeid);
		$trendsObj = $this->twitterObj->get_trends($parametros);
		$trends = array();

		$trendLocal = new Trends($trendsObj->response);
		if (is_array($trendsObj->response['trends'] )){
			foreach ($trendsObj->response['trends'] as $key => $value){
				$trend = new Trend($value);
				//add the trend to the array
				array_push($trends, $trend);
			}
			$trendLocal->trends = $trends;
		}
		

		return $trendLocal;
	}
	public function getTrendsAvailable(){
		$trendsObj = $this->twitterObj->get_trendsAvailable();

		$locations = array();
		foreach ($trendsObj->response as $key => $value){
			$location = new Location($value);
			//add the trend to the array
			array_push($locations, $location);
		}
		return $locations;
	}
}